<?php
namespace addons\csmonline\controller;

use addons\csmonline\library\CsmFrontend;
use addons\csmonline\library\CsmUtils;
use addons\csmonline\Csmonline;

class Index extends CsmFrontend
{

    protected $noNeedLogin = [
        '*'
    ];

    protected $noNeedRight = [
        '*'
    ];

    public function index()
    {
        $this->error("当前插件暂无前台页面");
    }

    public function touch()
    {
        $id = $this->csmreq("id", false);
        $sign = $this->csmreq("sign", false);
        $title = $this->csmreq("title", false);

        if ($id == null || $id == "" || $sign == null || $sign == "") {
            return;
        }
        if ($sign != md5($id)) {
            return;
        }

        $dao = new \app\admin\model\csmonline\Userlog();
        $row = $dao->where("id", "=", $id)->find();
        if ($row == null) {
            return;
        }

        $params = [
            "title" => CsmUtils::unescape($title),
            "durationseconds" => time() - $row->createtime,
            'durationlasttime' => time(),
            'durationlasthour' => date("H")
        ];
        $dao->where("id", "=", $id)->update($params);

        return;
    }

    public function point()
    {
        $csmonine = new Csmonline();
        $sr2 = $csmonine->_setPagePoint();

        $config = get_addon_config("csmonline");
        $heartseconds = (int) $config["heartseconds"];
        $heartmseconds = $heartseconds * 1000;
        $heartmseconds = 10000;
        
        return $this->csmjson(['id'=>$sr2['id'],'sign'=>md5($sr2['id']),'heartmseconds'=>$heartmseconds]);
    }
}
